home *** CD-ROM | disk | FTP | other *** search
- ;**************************************************************************
- ;* *
- ;* Written by: Fred Richards (VE7FIT) *
- ;* Date: August 18, 1991 *
- ;* *
- ;* This software is FREEWARE, as long as my name is given in *
- ;* the credits for the software developed using it. *
- ;* *
- ;* Assemble using Microsoft Macro Assembler *
- ;* *
- ;* MASM GAMEPORT; *
- ;* *
- ;* or Borland Turbo Assembler *
- ;* *
- ;* TASM GAMEPORT *
- ;* *
- ;**************************************************************************
-
- ;**************************************************************************
- ;* *
- ;* The following routines allow the user to read the position *
- ;* of the Joy Stick. Typical numbers range from 8 to 300. *
- ;* *
- ;* 8 sticky() *
- ;* | *
- ;* | *
- ;* 8 ----- * ----- 300 stickx() *
- ;* | *
- ;* | *
- ;* 300 *
- ;* *
- ;**************************************************************************
-
- .MODEL SMALL, C
- .CODE
-
- PUBLIC stickx, sticky, button1, button2
-
- stickx PROC NEAR
- push dx ; Save DX
- push bx ; Save BX
- mov bx,0 ; Set initial count to zero
- mov dx,0201h ; Set DX to game port
- out dx,al ; Start the timers (Any output will do)
- stickx1:in al,dx ; Get port status
- inc bx ; Increment counter
- and al,01h ; Test if x-timer has timed out
- jnz short stickx1 ; Loop if not
- mov ax,bx ; Load AX with counter value (for return)
- pop bx ; Restore BX
- pop dx ; Restore DX
- ret
-
- stickx endp
-
-
- sticky PROC NEAR ; See above for comments
- push dx
- push bx
- mov bx,0
- mov dx,0201h
- out dx,al
- sticky1:in al,dx
- inc bx
- and al,02h ; Test if y-timer has timed out
- jnz short sticky1
- mov ax,bx
- pop bx
- pop dx
- ret
-
- sticky endp
-
- ;**************************************************************************
- ;* *
- ;* The following routines allow the user to read the Joy Stick *
- ;* buttons. 0 = Not pressed, 1 = Pressed. *
- ;* *
- ;**************************************************************************
-
- button1 PROC NEAR ; This is normally the MAIN button
- push dx ; Save DX
- mov dx,0201h ; Load DX with game port address
- mov ah,0 ; Zero upper half of AX
- in al,dx ; Read game port
- not al ; Flip bits
- and al,10h ; Mask to button #1
- jz buttonz ; Skip if not pressed
- mov al,1 ; Set 1 for return value (button pressed)
- buttonz:pop dx ; Restore DX
- ret
-
- button1 endp
-
- button2 PROC NEAR ; See above for comments
- push dx
- mov dx,0201h
- mov ah,0
- in al,dx
- not al
- and al,20h ; Mask for button #2
- jz buttony
- mov al,1
- buttony:pop dx
- ret
-
- button2 endp
-
- end
-